﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using KZ.Lottery.Entities;
using KZ.Lottery.Report;
using KZ.Lottery.Resources;
using KZ.Utilities;
using System.Data;

namespace KZ.Lottery
{
    public partial class FrmPreview : Form
    {
        public FrmPreview()
        {
            InitializeComponent();
        }

        private void FrmPreview_Load(object sender, EventArgs e)
        {
            switch (ReportType)
            {
                case "ReportByRuleChannel":
                    LoadReportByRuleChannel();
                    break;
                case "ReportByChannel":
                    LoadReportByChannel();
                    break;
                case "ReportByChannelTotal":
                    LoadReportByChannelTotal();
                    break;
                case "ReportByDate":
                    LoadReportByDate();
                    break;
            }
        }

        private void LoadReportByRuleChannel()
        {
            RptByRuleChannel rptByRuleChannel = new RptByRuleChannel();
            rptByRuleChannel.SetDataSource(DT);

            if (FromStart)
            {
                rptByRuleChannel.SetParameterValue(rptByRuleChannel.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByRuleChannel.SetParameterValue(rptByRuleChannel.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByRuleChannel;
        }

        private void LoadReportByChannel()
        {
            RptByChannel rptByChannel = new RptByChannel();
            rptByChannel.SetDataSource(DT);

            if (FromStart)
            {
                rptByChannel.SetParameterValue(rptByChannel.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByChannel.SetParameterValue(rptByChannel.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByChannel;
        }

        private void LoadReportByChannelTotal()
        {
            RptByChannelTotal rptByChannelTotal = new RptByChannelTotal();
            rptByChannelTotal.SetDataSource(DT);

            if (FromStart)
            {
                rptByChannelTotal.SetParameterValue(rptByChannelTotal.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByChannelTotal.SetParameterValue(rptByChannelTotal.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByChannelTotal;
        }

        private void LoadReportByDate()
        {
            RptByDate rptByDate = new RptByDate();
            rptByDate.SetDataSource(DT);

            if (FromStart)
            {
                rptByDate.SetParameterValue(rptByDate.Parameter_lblReportTitle.ParameterFieldName,
                    KZ_Resource.Report);
            }
            else
            {
                rptByDate.SetParameterValue(rptByDate.Parameter_lblReportTitle.ParameterFieldName,
                    String.Format(KZ_Resource.ReportFromTo, From.ToShortPattern(Global.Culture), To.ToShortPattern(Global.Culture)));
            }

            crystalReportViewer1.ReportSource = rptByDate;
        }

        public DataTable DT { get; set; }

        public string ReportType { get; set; }

        public DateTime From { get; set; }

        public DateTime To { get; set; }

        public bool FromStart { get; set; }
    }
}